package com.jiepos.mpos.biz.review.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.affix.service.AppAffixInfService;
import com.jiepos.mpos.biz.customer.service.AppCustomerInfoService;
import com.jiepos.mpos.biz.customer.service.CustomBankcardInfoService;
import com.jiepos.mpos.biz.review.service.MemReviewService;
import com.jiepos.mpos.common.entity.App_Menu_CdEntity;
import com.jiepos.mpos.common.entity.MemReviewEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;
import com.jiepos.mpos.core.util.StringUtils;

/**
 * 实名认证待办事项控制层
 * @ClassName: ReviewHomePageController
 * @Description: 审核管理控制层
 * @author 张磊
 * @date 2017年9月21日 下午3:03:34
 *
 */
@Controller
@RequestMapping("memreview")
public class MemReviewController extends BaseController{

	@Autowired
	private MemReviewService memReviewService;
	
	@Autowired
	private AppCustomerInfoService appCustomerInfoService;
	
	@Autowired
	private CustomBankcardInfoService customBankcardInfoService;
	
	@Autowired
	private AppAffixInfService appAffixInfService;
	
	/**
	 * 跳转到实名认证待办事项页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/jumpToMemReview.do")
	public ModelAndView jumpToMemReview(HttpServletRequest request, HttpServletResponse response){
		Map map=super.getLoginUser(request, response);
		App_Menu_CdEntity app_Menu_CdEntity = memReviewService.getMenuCode("memreview/getMemReviewList.do");
		map.put("menuCode", app_Menu_CdEntity.getMenu_uuid());
		return new ModelAndView(new RedirectView("getMemReviewList.do"), map);
	}
	
	
	/**
	 * 进入实名认证待办事项页面
	 * 
	 * @param request
	 * @param response
	 * @param pagination
	 * @return
	 */
	@RequestMapping("/getMemReviewList.do")
	public ModelAndView getMenuIndexList(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination, MemReviewEntity memReviewEntity) {
		ModelAndView model = new ModelAndView("/module/review/membercertifi/membercertifi_list");
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 获取实名认证待办事项Json
	 * @param request
	 * @param response
	 * @param pagination
	 * @param memReviewEntity
	 * @return
	 */
	@RequestMapping("/getMemReviewListJson.do")
	public @ResponseBody Map getMemReviewListJson(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination,MemReviewEntity memReviewEntity){
		return memReviewService.getMemReviewList(pagination,request,memReviewEntity);
	}
	
	
	/**
	 * 获取会员详细信息
	 * @param custom_uuid
	 * @return
	 */
	@RequestMapping("/reviewMemInfo.do")
	public ModelAndView getCustomerDetail(HttpServletRequest request, HttpServletResponse response, String custom_uuid){
		ModelAndView modelAndView = new ModelAndView("/module/review/membercertifi/reviewMemInfo_review");
		Map appCustomBankEntity = customBankcardInfoService.getNewestCustomBankcard(custom_uuid);
		modelAndView.addObject("custom_uuid",custom_uuid);
		modelAndView.addObject("appCustomBankEntity", appCustomBankEntity);
		return super.getDetail(request, response, modelAndView);
	}
	
	/**
	 * 获取会员信息
	 * @param request
	 * @param response
	 * @param custom_uuid
	 * @return
	 */
	@RequestMapping("/getMemReviewCommonDetail.do")
	public ModelAndView getMemReviewDoneCommonDetail(HttpServletRequest request, HttpServletResponse response, String custom_uuid){
		ModelAndView modelAndView = new ModelAndView("/module/customer/customerinfo/customerinfo_common_detail");
		if(!StringUtils.isEmpty(custom_uuid)){
			Map customInfEntity = appCustomerInfoService.getCustomerInfoByUUID(custom_uuid);
			Map appCustomBankEntity = customBankcardInfoService.getNewestCustomBankcard(custom_uuid);
			List<Map<String, Object>> picList = appAffixInfService.getCustomCertificatePic(custom_uuid);
			modelAndView.addObject("appCustomerInfEntity", customInfEntity);
			modelAndView.addObject("appCustomBankEntity", appCustomBankEntity);
			modelAndView.addObject("picList", picList);
		}
		return super.getDetail(request, response, modelAndView);
	}
	
	
	
	
	/**
	 * 审核通过操作
	 * @param request
	 * @param response
	 * @param pagination
	 * @param app_WorkFlow_TraceEntity
	 * @param app_Custom_BankcardEntity
	 * @param custom_uuid
	 * @param bankcard_uuid
	 * @return
	 */
	@RequestMapping("/memReviewPass.do")
	public ModelAndView memReviewPass(HttpServletRequest request, HttpServletResponse response,String audit_comments,String custom_uuid,String bankcard_uuid){
		
		Map map=super.getLoginUser(request, response);	
		memReviewService.memReviewPass(audit_comments,custom_uuid,bankcard_uuid,map);
		
		return new ModelAndView(new RedirectView("getMemReviewList.do"), map);
	}
	
	
	/**
	 * 返回修改操作
	 * @param request
	 * @param response
	 * @param audit_comments
	 * @return
	 */
	@RequestMapping("/memReviewBack.do")
	public ModelAndView memReviewBack(HttpServletRequest request, HttpServletResponse response,String audit_comments,String custom_uuid){
		
		Map map=super.getLoginUser(request, response);	
		memReviewService.memReviewBack(audit_comments,custom_uuid,map);
		
		return new ModelAndView(new RedirectView("getMemReviewList.do"), map);
	} 
	
	/**
	 * 获取审核详细信息
	 * @param request
	 * @param response
	 * @param custom_uuid
	 * @return
	 */
	@RequestMapping("/getMemReviewDetail.do")
	public ModelAndView getMemReviewDetail(HttpServletRequest request, HttpServletResponse response, String custom_uuid){
		ModelAndView modelAndView = new ModelAndView("/module/review/membercertifi/reviewMemInfo_detail");
		modelAndView.addObject("custom_uuid",custom_uuid);
		return super.getDetail(request, response, modelAndView);
	}
	
	/**
	 * 校验用户审核状态和银行卡状态
	 * @param custom_uuid
	 * @param bankcard_uuid
	 * @return
	 */
	@RequestMapping("/checkCustomInfo.do")
	@ResponseBody
	public String checkCustomInfo(String custom_uuid,String bankcard_uuid){
		
		return memReviewService.checkCustomInfo(custom_uuid,bankcard_uuid);
	}
	
}
